<template>
  <el-col :span="span">
    <el-form-item :label="labelName" class="cust-label" style="text-align: left;">
      <el-tag
        :key="tag"
        v-for="tag in dynamicTags"
        closable
        :disable-transitions="false"
        @close="handleClose(tag)"
      >{{tag}}</el-tag>
    </el-form-item>
  </el-col>
</template>
<script>
export default {
  props: {
    // 接收页面初始化数据
    getVal: { type: String, default: "" },
    codeField: { type: String, default: "" },
    lookuptype: { type: String, default: "DB0043" },
    labelName:{type:String,default:"接收人手机号"},
    span: { type: Number, default: 24 }
  },
  data() {
    return {
      dynamicTags: this.getData(),
      inputValue: "",
      inputVisible: false
    };
  },
  //监听标签值
  watch: {
    dynamicTags(value) {
      debugger;
      let val = value.join(",");
      var parent = this.$utils.getHasFormFieldParentComponent(this);
      parent.formField[this.codeField] = val;
      this.$emit("changeCode", value);
    }
  },
  mounted(){
    this.$nextTick(() => {
      // this.getData();
    });
  },
  methods: {
    // 点击选择标签
    handleClose(tag) {
      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
    },
    handleInputConfirm() {
      let inputValue = this.inputValue;
      if (inputValue) {
        this.dynamicTags.push(inputValue);
      }
      this.inputVisible = false;
      this.inputValue = "";
    },
    // 初始化
    getData() {
      let that = this;
      var parent = this.$utils.getHasFormFieldParentComponent(this);
      let val=[]
      if(parent.formField[this.codeField]!=""){
        val = parent.formField[this.codeField].split(",");
      }
      return val;
      // for (let i = 0; i < this.interestList.length; i++) {
      //   for (let j = 0; j < val.length; j++) {
      //     if (this.interestList[i].lookupValueName == val[j]) {
      //       this.interestList[i].checked = true;
      //     }
      //   }
      // }
    }
  }
};
</script>
<style scoped>
.filter-params-crm .cust-label label{
  width:10%;
}
.filter-params-crm{
  text-align:left
}
</style>